clear

load Results_baseline_noFees.mat

mu = 0.085;
growth_rates = [0 , mu , 2*mu];

Alpha_path_LSF = Alpha_star_LSF * ones(T,1);        % "path" for optimal (time-invariant) equity exposure in LSF.
B_path_fixed = B_star_fixed * ones(T,1);            % "path" for optimal (time-invariant) buffer level in RILA.
F_path_fixed = F_star_fixed * ones(T,1);            % "path" for optimal (time-invariant) floor level in RILA.

Alpha_path_TDF = zeros(T,length(growth_rates));     % paths for optimal equity exposure in TDF.
    Alpha_path_TDF(1,:) = Alpha_star_0_TDF;     
B_path_TDRILA = zeros(T,length(growth_rates));      % paths for optimal buffer level in TD-RILA.
    B_path_TDRILA(1,:) = B_star_0_TDRILA;       
F_path_TDRILA = zeros(T,length(growth_rates));      % paths for optimal buffer level in TD-RILA.
    F_path_TDRILA(1,:) = F_star_0_TDRILA;       

B_path_ETDRILA = zeros(T,length(growth_rates));     % paths for optimal buffer level in ETD-RILA with buffer.
    B_path_ETDRILA(1,:) = B_star_0_ETDRILA;    
Pu_path_ETDRILA_B = zeros(T,length(growth_rates));  % paths for optimal upside participation rate in ETD-RILA with buffer.
    Pu_path_ETDRILA_B(1,:) = Pu_star_0_ETDRILA_B;  
Pd_path_ETDRILA_B = zeros(T,length(growth_rates));  % paths for optimal downside participation rate in ETD-RILA with buffer.
    Pd_path_ETDRILA_B(1,:) = Pd_star_0_ETDRILA_B;  

F_path_ETDRILA = zeros(T,length(growth_rates));     % paths for optimal floor level in ETD-RILA with floor.
    F_path_ETDRILA(1,:) = F_star_0_ETDRILA;    
Pu_path_ETDRILA_F = zeros(T,length(growth_rates));  % paths for optimal upside participation rate in ETD-RILA with floor.
    Pu_path_ETDRILA_F(1,:) = Pu_star_0_ETDRILA_F;  
Pd_path_ETDRILA_F = zeros(T,length(growth_rates));  % paths for optimal downside participation rate in ETD-RILA with floor.
    Pd_path_ETDRILA_F(1,:) = Pd_star_0_ETDRILA_F;  


%% Find optimal investment behavior along specific paths (= evolutions of QRP account value) 
for g = 1:length(growth_rates)
    
    % Create path of QRP account values at which to evaluate optimal investment behavior 
    growth_rate = growth_rates(g);
    A_path = zeros(T-1,1);
    A_path(1) = I_0 * exp(growth_rate);
    for t=2:T-1
        I_tminus1 = I_0 * (1+g_I)^(t-1);
        A_path(t) = ( A_path(t-1) + I_tminus1 ) * exp(growth_rate);
    end
    
    % find optimal TDF equity exposure along path:
    for t=2:T
        Alpha_path_TDF(t,g) = interp1(A_grid,Alpha_star_mat_TDF(:,t-1),A_path(t-1));
    end
    
    % find optimal TD-RILA Buffer levels along path:
    for t=2:T
        B_path_TDRILA(t,g) = interp1(A_grid,B_star_mat_TDRILA(:,t-1),A_path(t-1));
    end

    % find optimal TD-RILA Floor levels along path:
    for t=2:T
        F_path_TDRILA(t,g) = interp1(A_grid,F_star_mat_TDRILA(:,t-1),A_path(t-1));
    end

    % Leveraged E-TD-RILA with Buffer:
    for t=2:T
        B_path_ETDRILA(t,g) = interp1(A_grid,B_star_mat_ETDRILA(:,t-1),A_path(t-1));
        Pu_path_ETDRILA_B(t,g) = interp1(A_grid,Pu_star_mat_ETDRILA_B(:,t-1),A_path(t-1));
        Pd_path_ETDRILA_B(t,g) = interp1(A_grid,Pd_star_mat_ETDRILA_B(:,t-1),A_path(t-1));
    end

    % Leveraged E-TD-RILA with Floor:
    for t=2:T
        F_path_ETDRILA(t,g) = interp1(A_grid,F_star_mat_ETDRILA(:,t-1),A_path(t-1));
        Pu_path_ETDRILA_F(t,g) = interp1(A_grid,Pu_star_mat_ETDRILA_F(:,t-1),A_path(t-1));
        Pd_path_ETDRILA_F(t,g) = interp1(A_grid,Pd_star_mat_ETDRILA_F(:,t-1),A_path(t-1));
    end

end


%% Create Figures
xx = -T:-1;

% Figure 1(a): Path of optimal equity exposure for TDF
figure()
hold on
plot(xx,Alpha_path_TDF(:,1),'--','LineWidth',2,'Color','blue')
plot(xx,Alpha_path_TDF(:,2),'-','LineWidth',2,'Color','red')
plot(xx,Alpha_path_TDF(:,3),'-.','LineWidth',2,'Color','green')
plot(xx,Alpha_path_LSF,':','LineWidth',2,'Color','black')
hold off
ax = gca;
ax.FontSize = 14; 
legend('TDF: low A_t','TDF: average A_t','TDF: high A_t','LSF','Location','best')
% legend('Location','southeast')
xlabel('Years to Retirement','FontSize',16,'FontWeight','bold')
ylabel('\alpha_t^*        ','FontSize',16,'FontWeight','bold')
set(get(gca,'YLabel'),'Rotation',0)
xlim([-40,1])
ylim([0,1])
yticks(0:0.2:1)


% Figure 1(b): Path of optimal buffer level for TD-RILA
figure()
hold on
plot(xx,B_path_TDRILA(:,1),'--','LineWidth',2,'Color','blue')
plot(xx,B_path_TDRILA(:,2),'-','LineWidth',2,'Color','red')
plot(xx,B_path_TDRILA(:,3),'-.','LineWidth',2,'Color','green')
plot(xx,B_path_fixed,':','LineWidth',2,'Color','black')
hold off
ax = gca;
ax.FontSize = 14; 
legend('TD-RILA: low A_t','TD-RILA: average A_t','TD-RILA: high A_t','RILA','Location','best')
xlabel('Years to Retirement','FontSize',16,'FontWeight','bold')
ylabel('B_t^*        ','FontSize',16,'FontWeight','bold')
set(get(gca,'YLabel'),'Rotation',0)
xlim([-40,1])
ylim([0,0.15])
yticks(0:0.02:0.14)


% Figure 1(c): Path of optimal floor level for TD-RILA
figure()
hold on
plot(xx,F_path_TDRILA(:,1),'--','LineWidth',2,'Color','blue')
plot(xx,F_path_TDRILA(:,2),'-','LineWidth',2,'Color','red')
plot(xx,F_path_TDRILA(:,3),'-.','LineWidth',2,'Color','green')
plot(xx,F_path_fixed,':','LineWidth',2,'Color','black')
hold off
ax = gca;
ax.FontSize = 14; 
legend('TD-RILA: low A_t','TD-RILA: average A_t','TD-RILA: high A_t','RILA','Location','best')
xlabel('Years to Retirement','FontSize',16,'FontWeight','bold')
ylabel('F_t^*        ','FontSize',16,'FontWeight','bold')
set(get(gca,'YLabel'),'Rotation',0)
xlim([-40,1])
ylim([0,0.6])
yticks(0:0.1:0.6)


% Figure 2(a1): Path of optimal participation rates for ETD-RILA with buffer 
figure()
hold on
xlim([-40,1])
ax = gca;
ax.FontSize = 14; 
xlabel('Years to Retirement','FontSize',16,'FontWeight','bold')
plot(xx,Pu_path_ETDRILA_B(:,2),'--','LineWidth',2,'Color','blue')
plot(xx,Pd_path_ETDRILA_B(:,2),'-.','LineWidth',2,'Color','green')
ylabel('Participation Rates','FontSize',16,'FontWeight','bold')
ylim([0,1.5])
yticks(0:0.3:1.5)
hold off
legend('E-TD-RILA: P^u_t','E-TD-RILA: P^d_t','Location','ne')


% Figure 2(a2): Path of optimal buffer level for ETD-RILA with buffer 
figure()
hold on
xlim([-40,1])
ax = gca;
ax.FontSize = 14; 
xlabel('Years to Retirement','FontSize',16,'FontWeight','bold')
plot(xx,B_path_ETDRILA(:,2),'-','LineWidth',2,'Color','red')
plot(xx,B_path_TDRILA(:,2),':','LineWidth',2,'Color','black')
ylabel('Buffer','FontSize',16,'FontWeight','bold')
ylim([0,0.15])
yticks(0:0.025:0.15)
hold off
legend('E-TD-RILA: B_t','TD-RILA: B_t','Location','ne')


% Figure 2(b): Path of optimal participation rates and floor level for ETD-RILA with floor 
figure()
hold on
plot(xx,F_path_ETDRILA(:,2),'-','LineWidth',2,'Color','red')
plot(xx,Pu_path_ETDRILA_F(:,2),'--','LineWidth',2,'Color','blue')
plot(xx,Pd_path_ETDRILA_F(:,2),'-.','LineWidth',2,'Color','green')
plot(xx,F_path_TDRILA(:,2),':','LineWidth',2,'Color','black')
hold off
ax = gca;
ax.FontSize = 14; 
legend('E-TD-RILA: F_t','E-TD-RILA: P^u_t','E-TD-RILA: P^d_t','TD-RILA: F_t','Location','best')
xlabel('Years to Retirement','FontSize',16,'FontWeight','bold')
ylabel('Optimal Investment','FontSize',16,'FontWeight','bold')
xlim([-40,1])
ylim([0,1.5])
yticks(0:0.3:1.5)

